//
//  XMPageViewController.m
//  gpos_app
//
//  Created by apple on 2018/8/13.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "XMPageViewController.h"
#import "Masonry.h"
#import "pageJxViewCell.h"
#import "jymimaViewController.h"
#import "canyujxViewController.h"
#import "GPosAPI.h"
#import "SVProgressHUD.h"
#import "homeModel.h"
#import "UIImageView+WebCache.h"
#import "XMRegisterViewController.h"
#import "MJRefresh.h"

#import "ZQCountdownTime.h"
#import "jxgzViewController.h"

@interface XMPageViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)UITableView * tableView;
@property (nonatomic,strong)UIView * headerBJView;
@property (nonatomic,strong)UIImageView * bjImageView;
@property (nonatomic,strong)UIView * contendBJView;
@property (nonatomic,strong)UILabel * cyrsLabel;
@property (nonatomic,strong)UILabel * zyeLsyabel;
@property (nonatomic,strong)UILabel * jxyeLsyabel;
@property (nonatomic,strong)UILabel * daojishiLabel;
@property (nonatomic,strong)UIButton * jingxuanButton;
@property (nonatomic,strong)UIView * footerBGView;
@property (nonatomic,strong)UIImageView * xingxingImage;
@property (nonatomic,strong)UILabel * zjshuziLabel;
@property (nonatomic,strong)UILabel * zjContentLabel;
@property (nonatomic,strong)UILabel * ziNameLabel;
@property (nonatomic,strong)UILabel * ziGPOSLabel;
@property (nonatomic,strong)NSDictionary * params;
@property (nonatomic,strong)UILabel * cankaoLabel;

@property (nonatomic,strong)NSString *  totalBalance;
@property (nonatomic,strong)NSString * JXBalance;
@property (nonatomic,assign)NSInteger stage;
@property (nonatomic,assign)NSInteger ison;
@property (nonatomic,assign)NSInteger firstNumber;
@property (nonatomic,assign)NSInteger secondNumber;
@property (nonatomic,assign)NSInteger thirdNumber;
@property (nonatomic,assign)NSInteger miniNumber;
@property (nonatomic,strong)NSString *  returnTime;
@property (nonatomic,strong)NSString *  lastAmount;
@property (nonatomic,assign)int user;
@property (nonatomic,assign)int page;
@property (nonatomic,assign)int phase;
@property (nonatomic,assign)float  totalSize;
@property (nonatomic,strong)UIButton *syyButton;
@property (nonatomic,strong)UIButton *xyyButton;

@property (nonatomic,assign)NSInteger   cutDownTime;

@property (nonatomic,strong)NSMutableArray *modelArr;

@property (nonatomic,strong)UIView *vv1;
@property (nonatomic,strong) NSString *str1;
@property (nonatomic,strong) NSString *str2;
@property (nonatomic,strong) UIView *qseView;
@property (nonatomic,strong)NSString * oneTotalSize;


@end

@implementation XMPageViewController

//倒计时总的秒数
//static NSInteger  secondsCountDown = 86400;

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];

    self.navigationController.navigationBar.hidden=YES;
   

}


- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor colorWithRed:244/255.0f green:244/255.0f blue:244/255.0f alpha:1];
    self.navigationController.navigationBar.hidden = YES;
    //隐藏返回提示文字
    self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:self action:nil];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(walkVCClick:) name:@"buttonLoseRespon" object:nil];
     self.oneTotalSize = @"";
    self.page = 1;
    [self toploadData];
    
}

- (void)walkVCClick:(NSNotification *)noti

{
    
    [self toploadData];
}
-(void)dealloc{
    
    [[NSNotificationCenter defaultCenter] removeObserver:self];

}

- (void)toploadData{
    [SVProgressHUD showWithStatus:@"加载中"];
    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
    [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
    __weak typeof(self) weakSelf = self;
    int user = [[[NSUserDefaults standardUserDefaults] objectForKey:@"userId"] intValue];
    self.params=[NSDictionary new];
    self.params = @{@"userId" : @(user)};
    dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
    // 创建全局并行
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    dispatch_group_t group = dispatch_group_create();
    dispatch_group_async(group, queue, ^{
        
        // 请求一
        [GPosAPI requestTotalBalanceWithParams:weakSelf.params andCallback:^(id obj) {
            NSLog(@"余额---%@",obj);
            if (obj == nil) {
                
                [self tableViewLoad];
            }else {
                
                if ([[obj objectForKey:@"code"] integerValue] ==200) {
                    //                    NSDictionary * arr = [obj objectForKey:@"data"];
//                    float num = [[[obj objectForKey:@"data"] objectForKey:@"totalBalance"] floatValue];
//                     NSNumber * nsNumber1 = @(num);
                    NSDecimalNumber * number = [[obj objectForKey:@"data"] objectForKey:@"totalBalance"];
                    NSLog(@"----nuss--%@",number);
//                    model.amount = [NSString stringWithFormat:@"%@",@(number.floatValue)];
                    self.totalBalance = [NSString stringWithFormat:@"%@",@(number.floatValue)];
                    
                    
                }else if ([[obj objectForKey:@"code"] integerValue] ==401 || [[obj objectForKey:@"code"] intValue] == 402){
                    UIStoryboard *mainStory = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
                    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"passWord"];
                    //storyboard里的ID
                    XMRegisterViewController *vc = [mainStory instantiateInitialViewController];
                    vc.navigationController.navigationBarHidden=NO;
                    //                    //设置当前窗口的根控制器
                    
                    [UIApplication sharedApplication].keyWindow.rootViewController=vc;
                    [SVProgressHUD showInfoWithStatus:[obj objectForKey:@"message"]];
                    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                    [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
                    
                }
                
            }
            dispatch_semaphore_signal(semaphore);
        }];
        
    });
    
    dispatch_group_async(group, queue, ^{
        //余额
        [GPosAPI requestBalanceWithParams:weakSelf.params andCallback:^(id obj) {
            NSLog(@"竞选余额---%@",obj);
            if (obj == nil) {
                
                
            }else {
                
                if ([[obj objectForKey:@"code"] integerValue] ==200) {
//                    float num = [[obj objectForKey:@"data"] floatValue];
//                     NSNumber * nsNumber1 = @(num);
                    NSDecimalNumber * number = [obj objectForKey:@"data"];
                    self.JXBalance = [NSString stringWithFormat:@"%@",@(number.floatValue)];
                    
                }else if ([[obj objectForKey:@"code"] integerValue] ==401 || [[obj objectForKey:@"code"] intValue] == 402){
                    UIStoryboard *mainStory = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
                    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"passWord"];
                    //storyboard里的ID
                    XMRegisterViewController *vc = [mainStory instantiateInitialViewController];
                    vc.navigationController.navigationBarHidden=NO;
                    //                    //设置当前窗口的根控制器
                    
                    [UIApplication sharedApplication].keyWindow.rootViewController=vc;
                    [SVProgressHUD showInfoWithStatus:[obj objectForKey:@"message"]];
                    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                    [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
                    
                }else {
                    [SVProgressHUD showErrorWithStatus:[obj objectForKey:@"message"]];
                    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                    [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
                    
                }
                
            }
            
            dispatch_semaphore_signal(semaphore);
        }];
        
        
    });
    
    
    dispatch_group_async(group, queue, ^{
        //是否开起竞选
        NSDictionary * params = @{@"" : @""};
        [GPosAPI requestOpenWithParams:params andCallback:^(id obj) {
            NSLog(@"是否开启---%@",obj);
            if (obj == nil) {
                
                
            }else {
                
                if ([[obj objectForKey:@"code"] integerValue] ==200) {
                    NSLog(@"obj---%@",obj);
                    self.stage = 1;
                    self.ison = 2;
                    self.lastAmount = [[obj objectForKey:@"data"] objectForKey:@"lastAmount"];
                    self.phase = [[[obj objectForKey:@"data"] objectForKey:@"phase"] intValue];
                    self.cutDownTime = [[[obj objectForKey:@"data"] objectForKey:@"cutDownTime"] integerValue];
                }else if ([[obj objectForKey:@"code"] integerValue] ==100){
                    //                    self.stage = 0;
                    self.ison = 0;
                    
                    
                }else if ([[obj objectForKey:@"code"] integerValue] ==401 || [[obj objectForKey:@"code"] intValue] == 402){
                    
                    UIStoryboard *mainStory = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
                    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"passWord"];
                    //storyboard里的ID
                    XMRegisterViewController *vc = [mainStory instantiateInitialViewController];
                    vc.navigationController.navigationBarHidden=NO;
                    //                    //设置当前窗口的根控制器
                    
                    [UIApplication sharedApplication].keyWindow.rootViewController=vc;
                    [SVProgressHUD showInfoWithStatus:[obj objectForKey:@"message"]];
                    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                    [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
                    
                }
                
            }
            
            dispatch_semaphore_signal(semaphore);
        }];
        
    });
    
    dispatch_group_notify(group, queue, ^{
        
        // 三个请求对应三次信号等待
        dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
        dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
        dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
        
        //在这里 进行请求后的方法，回到主线程
        dispatch_async(dispatch_get_main_queue(), ^{
            [SVProgressHUD dismiss];
            //更新UI操作
            
            [self tableViewLoad];
        });
        
        
    });
    
    
    
}

- (void)tableViewLoad{
    
    self.tableView = [[UITableView alloc] init];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    self.tableView.mj_header=[MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(toploadData)];
    
    [self.view addSubview:self.tableView];
    if (iPhoneX) {
        [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.view).with.offset(0);
            make.top.equalTo(self.view).with.offset(-44);
            make.right.equalTo(self.view).with.offset(0);
            make.bottom.equalTo(self.view).with.offset(-kSystemNavHeight);
        }];
        
    }else {
        [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.view).with.offset(0);
            make.top.equalTo(self.view).with.offset(0);
            make.right.equalTo(self.view).with.offset(0);
            make.bottom.equalTo(self.view).with.offset(-49);
        }];
        
    }
    
   
    [self headerViewLoad];
    [self contendLoadView];
    [self footerLoadView];
     [self loadData];
    
}

- (void)loadData{
    
    if (self.ison == 0) {
        NSLog(@"请求phase");
        self.bjImageView.image = [UIImage imageNamed:@"banner_msjx"];
        self.jingxuanButton.userInteractionEnabled = NO;
        self.jingxuanButton.layer.cornerRadius  = 10;
        [self.jingxuanButton setBackgroundImage:[UIImage imageNamed:@"icon_anniu_jx_h"] forState:UIControlStateNormal];
        NSDictionary * params = @{@"" : @""};
        [GPosAPI requestPhaseWithParams:params andCallback:^(id obj) {
            NSLog(@"obj--%@",obj);
            
            if (obj == nil) {
                
            }else {
                
                NSDictionary *dic = [obj objectForKey:@"data"];
                if ([[obj objectForKey:@"code"] integerValue] ==200) {
                    self.stage = 2;
                    if ([[dic objectForKey:@"firstNumber"] isMemberOfClass:[NSNull class]] ) {
                        self.firstNumber = 0;

                    }else {

                        self.firstNumber = [[dic objectForKey:@"firstNumber"] integerValue];

                    }
                    
                    if ([[dic objectForKey:@"miniNumber"] isMemberOfClass:[NSNull class]] ) {
                        self.miniNumber = 0;
                        
                    }else {
                        
                        self.miniNumber = [[dic objectForKey:@"miniNumber"] integerValue];
                        
                    }
                    if ([[dic objectForKey:@"secondNumber"] isMemberOfClass:[NSNull class]] ) {
                        self.secondNumber = 0;
                        
                    }else {
                        
                        self.secondNumber = [[dic objectForKey:@"secondNumber"] integerValue];
                        
                    }
                    
                    if ([[dic objectForKey:@"thirdNumber"] isMemberOfClass:[NSNull class]] ) {
                        self.thirdNumber = 0;
                        
                    }else {
                        
                        self.thirdNumber = [[dic objectForKey:@"thirdNumber"] integerValue];
                        
                    }
//                    self.firstNumber = [[dic objectForKey:@"firstNumber"] integerValue];
//                                        self.miniNumber = [[dic objectForKey:@"miniNumber"] integerValue];
                    self.returnTime = [dic objectForKey:@"returnTime"];
//                                        self.secondNumber = [[dic objectForKey:@"secondNumber"] integerValue];
                    self.lastAmount = [dic objectForKey:@"lastAmount"];
//                    self.thirdNumber = [[dic objectForKey:@"thirdNumber"] integerValue];

//                     NSNumber * nsNumber1 = @(self.lastAmount);
                     self.cankaoLabel.text = [NSString stringWithFormat:@"上榜参考值：%@ GPOS",@(self.lastAmount.floatValue)];
                    [self loadRankData];
//                    [self.tableView reloadData];
                }else if ([[obj objectForKey:@"code"] integerValue] ==101){
                    
                    self.stage = -1;
                    self.daojishiLabel.textColor = [UIColor grayColor];
                    self.daojishiLabel.text = [NSString stringWithFormat:@"竞选未开启，目前GPOS智能总数 %d",[[[obj objectForKey:@"data"] objectForKey:@"miners"] intValue]];
                                               
                    [self loadRankData];
                
                    
                }
            }
          [self.tableView reloadData];
        }];
        
        
    }else if (self.ison == 2) {
        
        [[ZQCountdownTime  shareManage]countDownViewWithEndData:[NSDate dateWithTimeIntervalSinceNow:self.cutDownTime/1000] returnBlock:^(NSString *time) {
            NSLog(@"time====%@",time);
            self.daojishiLabel.text = [NSString stringWithFormat:@"本期 （第%d期）剩余截止时间：%@",self.phase,time];
        }];
         NSLog(@"time====%@",self.lastAmount);
//         NSNumber * nsNumber1 = @(self.lastAmount);
        if ([self.lastAmount isMemberOfClass:[NSNull class]]) {
            self.lastAmount = @"0";
            
        }
//        [NSString stringWithFormat:@"%@",@(number.floatValue)]
        self.cankaoLabel.text = [NSString stringWithFormat:@"上榜参考值：%@ GPOS",@(self.lastAmount.floatValue)];
//        NSLog(@"str----%ld",str1);
////
       
    
        [self loadRankData];
        NSLog(@"请求v");
        
    }
}

- (void)loadRankData{

    if (@(self.firstNumber) == nil) {
        self.firstNumber = 0;
    }
    if (@(self.secondNumber) == nil) {
        self.secondNumber = 0;
    }
    if (@(self.thirdNumber) == nil) {
        self.thirdNumber = 0;
    }
    int user = [[[NSUserDefaults standardUserDefaults] objectForKey:@"userId"] intValue];
    NSDictionary * params = @{@"userId" : @(user),
                              @"stage" : @(self.stage),
                              @"firstNumber" :@(self.firstNumber),
                              @"secondNumber" : @(self.secondNumber),
                              @"thirdNumber" : @(self.thirdNumber),
                              @"page" : @(self.page),
                              @"limit" : @(10)
                              };
    [GPosAPI requestRankViewWithParams:params andCallback:^(id obj) {
        NSLog(@"list---%@",obj);
        if (obj ==nil) {
            
            
        }else {
            
            if ([[obj objectForKey:@"code"] integerValue] ==200) {
                
                if ([obj objectForKey:@"data"] == nil) {
                    NSLog(@"12");
                     self.oneTotalSize = @"0";
                    return ;
                }
                if ([obj objectForKey:@"data"] == 0) {
                    NSLog(@"12");
                    self.oneTotalSize = @"0";
                    return ;
                }
                if ([[obj objectForKey:@"data"] objectForKey:@"totalSize"]==NULL) {
//                    self.totalSize = 0;
                    self.oneTotalSize = @"0";
                    self.cyrsLabel.text = @"参与人数：0人";
                }else {
                    self.cyrsLabel.text = [NSString stringWithFormat:@"参与人数:%@ 人",[[obj objectForKey:@"data"] objectForKey:@"totalSize"]];
                    self.totalSize = [[[obj objectForKey:@"data"] objectForKey:@"totalSize"] floatValue];

                    self.oneTotalSize = [NSString stringWithFormat:@"%@",@(self.totalSize)];
                }
               
                // timeStampString 是服务器返回的13位时间戳
                NSString *timeStampString  = self.returnTime;
                
                // iOS 生成的时间戳是10位
                NSTimeInterval interval=[timeStampString doubleValue] / 1000.0;
                NSDate *date  = [NSDate dateWithTimeIntervalSince1970:interval];
                
                NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
                [formatter setDateFormat:@"MM-dd HH:mm:ss"];
                NSString *dateString    = [formatter stringFromDate: date];

//                NSLog(@"stage---%d",self.stage);
                if (self.stage == 2 && self.miniNumber > [[[obj objectForKey:@"data"] objectForKey:@"totalSize"] integerValue]) {
                    self.daojishiLabel.text = [NSString stringWithFormat:@"下期竞选(%@)",dateString];
                    self.daojishiLabel.textColor = [UIColor grayColor];
                    
                
                    
                }else if (self.stage == 2 && self.miniNumber < [[[obj objectForKey:@"data"] objectForKey:@"totalSize"] intValue]){
//                    self.cutDownTime = 0;
//                    self.daojishiLabel.text = @"";
                    [[ZQCountdownTime  shareManage]countDownViewWithEndData:[NSDate dateWithTimeIntervalSinceNow:0] returnBlock:^(NSString *time) {
                        NSLog(@"time====%@",time);
                        self.daojishiLabel.text = [NSString stringWithFormat:@"本期 （第%d期）剩余截止时间：%@",self.phase,time];
                    }];
                    self.daojishiLabel.text = [NSString stringWithFormat:@"竞选余额将在%@，返还到您的账户",dateString];
                    self.daojishiLabel.textColor = [UIColor grayColor];
                    
                }
                NSLog(@"-----%@",[[obj objectForKey:@"data"] objectForKey:@"totalSize"]);
                NSDictionary * dict = [obj objectForKey:@"data"];
                if ([[[obj objectForKey:@"data"] objectForKey:@"totalSize"] integerValue]==0) {
                    
                    [self footerLoadView];
//                    self.footerBGView.frame = CGRectMake(0,0, KmainScreenWidth, 230);
//                    self.footerBGView.hidden = YES;
//                    UIView * qseView = [[UIView alloc] init];
//                    qseView.backgroundColor = [UIColor colorWithWhite:0.93 alpha:1];
//                    qseView.layer.cornerRadius = 5;
//
//                    [self.footerBGView addSubview:qseView];
//                    [qseView mas_makeConstraints:^(MASConstraintMaker *make) {
//                        make.top.equalTo(self.footerBGView).with.offset(-35);
//                        make.left.equalTo(self.footerBGView).with.offset(15);
//                        make.right.equalTo(self.footerBGView).with.offset(-15);
////                        make.bottom.equalTo(self.view).with.offset(-44);
//                        make.height.equalTo(@250);
//                    }];
//
//                    UIImageView * qsyimage = [[UIImageView alloc] init];
//                    [qseView addSubview:qsyimage];
//                    [qsyimage mas_makeConstraints:^(MASConstraintMaker *make) {
//                        make.centerX.equalTo(qseView);
//                        make.centerY.equalTo(qseView);
//                        make.height.equalTo(@80);
//                        make.width.equalTo(@80);
//                    }];
//                    qsyimage.image = [UIImage imageNamed:@"icon_zwmingxi"];
//
//                    UILabel * qsyLabel= [[UILabel alloc] init];
//                    qsyLabel.text = @"暂无数据";
//                    qsyLabel.font = [UIFont systemFontOfSize:13.f];
//                    qsyLabel.textColor = [UIColor grayColor];
//                    [qseView addSubview:qsyLabel];
//                    [qsyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//                        make.centerX.equalTo(qseView);
//                        make.top.equalTo(qsyimage.mas_bottom).with.offset(5);
//
//                    }];

                }else {
                   
                    
                    self.modelArr = [[NSMutableArray alloc] init];
                    
                    NSArray * arr = [[NSArray alloc] init];
                    arr = [dict objectForKey:@"rankPage"];
                    for (NSDictionary * dic in arr) {
                        homeModel *model = [[homeModel alloc] init];
                        NSDecimalNumber * number = [dic objectForKey:@"amount"];
                        NSLog(@"----nuss--%@",number);
                        model.amount = [NSString stringWithFormat:@"%@",@(number.floatValue)];
                       
                        model.nickName = [dic objectForKey:@"nickName"];
                        model.rank = [[dic objectForKey:@"rank"] intValue];
                        model.portrait = [dic objectForKey:@"portrait"];
                        [self.modelArr addObject:model];
                        //                                NSLog(@"图片--%@",model);
                    }
//                    [self.tableView reloadData];
//                    self.totalSize = [[[obj objectForKey:@"data"] objectForKey:@"totalSize"] floatValue];
                    //
                    float srrr = ceilf(self.totalSize/10) ;
                    NSLog(@"srrr--%.f",srrr);
                    
                    NSString *stringInt = [NSString stringWithFormat:@"%f",srrr];
                    if ([stringInt intValue] > self.page) {
                        self.xyyButton.userInteractionEnabled=YES;
                        [self.xyyButton setTitleColor:[UIColor blueColor]forState:UIControlStateNormal];
                    }else {
                        self.xyyButton.userInteractionEnabled=NO;
                        [self.xyyButton setTitleColor:[UIColor grayColor]forState:UIControlStateNormal];
                        
                    }
                    if (self.page > 1) {
                        self.syyButton.userInteractionEnabled=YES;
                        [self.syyButton setTitleColor:[UIColor blueColor]forState:UIControlStateNormal];
                    }else {
                        
                        self.syyButton.userInteractionEnabled=NO;
                        [self.syyButton setTitleColor:[UIColor grayColor]forState:UIControlStateNormal];
                    }
                    [self.tableView reloadData];
                }
                
        
                if ([[[dict objectForKey:@"selfRank"] objectForKey:@"rank"] intValue] == -1) {
                    self.zjContentLabel.text = @"未参与";
                    self.zjContentLabel.textColor = [UIColor grayColor];
                    self.ziNameLabel.text = [[dict objectForKey:@"selfRank"] objectForKey:@"nickName"];
                    self.ziNameLabel.textColor = [UIColor grayColor];
//                     float GPOS = [[[dict objectForKey:@"selfRank"] objectForKey:@"amount"] floatValue];
//                     NSNumber * nsNumber1 = @(GPOS);
                    self.ziGPOSLabel.text = [NSString stringWithFormat:@"%@",[[dict objectForKey:@"selfRank"] objectForKey:@"amount"]];
                    self.ziGPOSLabel.textColor = [UIColor grayColor];
                    self.xingxingImage.hidden = YES;

                    
                }else {
                    
                    
                    if ([[[dict objectForKey:@"selfRank"] objectForKey:@"prize"] intValue] == -1) {
                        self.xingxingImage.hidden = YES;
                        self.zjContentLabel.text = @"未选上";
                        self.zjContentLabel.textColor = [UIColor redColor];
                        self.ziNameLabel.text = [[dict objectForKey:@"selfRank"] objectForKey:@"nickName"];
                        self.ziNameLabel.textColor = [UIColor redColor];
//                        float GPOS = [[[dict objectForKey:@"selfRank"] objectForKey:@"amount"] floatValue];
//                         NSNumber * nsNumber1 = @(GPOS);
                        self.ziGPOSLabel.text = [NSString stringWithFormat:@"%@",[[dict objectForKey:@"selfRank"] objectForKey:@"amount"]];
                        self.ziGPOSLabel.textColor = [UIColor redColor];
                        self.zjshuziLabel.text =[NSString stringWithFormat:@"%@",[[dict objectForKey:@"selfRank"] objectForKey:@"rank"]];
                        self.zjshuziLabel.textColor = [UIColor redColor];
                        
                    }else {
                        
                        if ([[dict objectForKey:@"selfRank"] count]==0) {
                            
                            self.ziGPOSLabel.text= @"";
                            self.zjshuziLabel.text = @"";
                            return;
                        }
                        if (self.stage == 2) {
                            self.zjContentLabel.text = @"已选上";
                        }
                        self.zjContentLabel.textColor = [UIColor blueColor];
                        self.ziNameLabel.text = [[dict objectForKey:@"selfRank"] objectForKey:@"nickName"];
//                        float GPOS = [[[dict objectForKey:@"selfRank"] objectForKey:@"amount"] floatValue];
                        self.ziNameLabel.textColor = [UIColor blueColor];
//                         NSNumber * nsNumber1 = @(GPOS);
                        self.ziGPOSLabel.text = [NSString stringWithFormat:@"%@",[[dict objectForKey:@"selfRank"] objectForKey:@"amount"]];
                        self.ziGPOSLabel.textColor = [UIColor blueColor];
                        self.zjshuziLabel.text =[NSString stringWithFormat:@"%@",[[dict objectForKey:@"selfRank"] objectForKey:@"rank"]];
                        self.zjshuziLabel.textColor = [UIColor blueColor];
                        
                    }
                
                }
                
            
                
            }else {
                
                NSLog(@"123444");
                
            }
        
        }
    
    }];
    
    
}
- (void)headerViewLoad {
    self.headerBJView = [[UIView alloc] init];
    
    if (IS_IPHONE5) {
        
        self.headerBJView.frame = CGRectMake(0, 0, KmainScreenWidth, 452);
        
    }else if (iPhoneX) {
        self.headerBJView.frame = CGRectMake(0, 0, KmainScreenWidth, 557);
        
    }else {
        self.headerBJView.frame = CGRectMake(0, 0, KmainScreenWidth, 523);
        
    }
    
    self.headerBJView.backgroundColor = [UIColor colorWithRed:244/255.0f green:244/255.0f blue:244/255.0f alpha:1];
    //    self.headerBJView.backgroundColor = [UIColor lightGrayColor];
    //    self.headerBJView.alpha = 0.5;
    self.headerBJView.userInteractionEnabled = YES;
    self.tableView.tableHeaderView = self.headerBJView;
    
    self.bjImageView = [[UIImageView alloc] init];
    self.bjImageView.image = [UIImage imageNamed:@"banner_zzjx"];
    UIButton * guizeButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [guizeButton setTitle:@"竞选规则" forState:UIControlStateNormal];
    [guizeButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    guizeButton.titleLabel.font = [UIFont systemFontOfSize: 14.0];
    [guizeButton addTarget:self action:@selector(guizeButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.bjImageView addSubview:guizeButton];
    
    
    //开启按钮的点击
    self.bjImageView.userInteractionEnabled = YES;
    [self.headerBJView addSubview:self.bjImageView];
    
    self.contendBJView = [[UIView alloc] init];
    self.contendBJView.backgroundColor = [UIColor whiteColor];
    self.contendBJView.layer.cornerRadius = 8;
    self.contendBJView.layer.masksToBounds = YES;
    [self.headerBJView addSubview:self.contendBJView];
    
    UILabel * jxpmLabel = [[UILabel alloc] init];
    jxpmLabel.text = @"竞选排名";
    jxpmLabel.textColor = [UIColor blackColor];
    jxpmLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:16];
    [self.headerBJView addSubview:jxpmLabel];
    
    UIView * leftView = [[UIView alloc] init];
    leftView.backgroundColor = [UIColor blackColor];
    [self.headerBJView addSubview:leftView];
    
    UIView * rightView = [[UIView alloc] init];
    rightView.backgroundColor = [UIColor blackColor];
    [self.headerBJView addSubview:rightView];
    
    self.cyrsLabel = [[UILabel alloc] init];
    self.cyrsLabel.textColor = [UIColor grayColor];
    self.cyrsLabel.font = [UIFont systemFontOfSize:12];
    [self.headerBJView addSubview:self.cyrsLabel];
    
    self.cankaoLabel = [[UILabel alloc] init];
    self.cankaoLabel.textColor = [UIColor grayColor];
    self.cankaoLabel.font = [UIFont systemFontOfSize:12];
    [self.headerBJView addSubview:self.cankaoLabel];
    
    UIView *cellTopView = [[UIView alloc] init];
    cellTopView.backgroundColor =  [UIColor colorWithRed:70/255.0f green:85/255.0f blue:254/255.0f alpha:1];
    cellTopView.layer.cornerRadius = 3;
    cellTopView.layer.masksToBounds = YES;
    [self.headerBJView addSubview:cellTopView];
    
    UILabel * oneLabel = [[UILabel alloc] init];
    oneLabel.text = @"名次";
    oneLabel.textColor = [UIColor whiteColor];
    oneLabel.textAlignment=NSTextAlignmentCenter;
    oneLabel.font = [UIFont systemFontOfSize:13];
    [cellTopView addSubview:oneLabel];
    
    UILabel * twoLabel = [[UILabel alloc] init];
    twoLabel.text = @"昵称";
    twoLabel.textAlignment=NSTextAlignmentCenter;
    twoLabel.textColor = [UIColor whiteColor];
    twoLabel.font = [UIFont systemFontOfSize:13];
    [cellTopView addSubview:twoLabel];
    
    UILabel * threeLabel = [[UILabel alloc] init];
    threeLabel.text = @"GPOS";
    threeLabel.textAlignment=NSTextAlignmentCenter;
    threeLabel.textColor = [UIColor whiteColor];
    threeLabel.font = [UIFont systemFontOfSize:13];
    [cellTopView addSubview:threeLabel];
    
    UIView * oneView = [[UIView alloc] init];
    oneView.backgroundColor = [UIColor whiteColor];
    [cellTopView addSubview:oneView];
    
    UIView * twoView = [[UIView alloc] init];
    twoView.backgroundColor = [UIColor whiteColor];
    [cellTopView addSubview:twoView];
    
    
    
    if (iPhoneX) {
        
        [self.bjImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.headerBJView).with.offset(0);
            make.left.equalTo(self.headerBJView).with.offset(0);
            make.right.equalTo(self.headerBJView).with.offset(0);
        }];
        
        [guizeButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.bjImageView).with.offset(30);
            make.right.equalTo(self.bjImageView).with.offset(-15);
        }];
        
        [self.contendBJView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.bjImageView.mas_bottom).with.offset(15);
            make.left.equalTo(self.headerBJView).with.offset(15);
            make.right.equalTo(self.headerBJView).with.offset(-15);
            make.height.equalTo(@220);
        }];
        
    }else if(IS_IPHONE5) {
        
        [self.bjImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.headerBJView).with.offset(-20);
            make.left.equalTo(self.headerBJView).with.offset(0);
            make.right.equalTo(self.headerBJView).with.offset(0);
            make.height.equalTo(@150);
            
        }];
        
        [guizeButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.bjImageView).with.offset(25);
            make.right.equalTo(self.bjImageView).with.offset(-15);
        }];
        
        [self.contendBJView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.bjImageView.mas_bottom).with.offset(15);
            make.left.equalTo(self.headerBJView).with.offset(15);
            make.right.equalTo(self.headerBJView).with.offset(-15);
            make.height.equalTo(@200);
        }];
        
    }else {
        
        [self.bjImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.headerBJView).with.offset(-20);
            make.left.equalTo(self.headerBJView).with.offset(0);
            make.right.equalTo(self.headerBJView).with.offset(0);
            
        }];
        
        [guizeButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.bjImageView).with.offset(25);
            make.right.equalTo(self.bjImageView).with.offset(-15);
        }];
        
        [self.contendBJView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.bjImageView.mas_bottom).with.offset(15);
            make.left.equalTo(self.headerBJView).with.offset(15);
            make.right.equalTo(self.headerBJView).with.offset(-15);
            make.height.equalTo(@220);
        }];
    }
    
    [jxpmLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contendBJView.mas_bottom).with.offset(26);
        make.centerX.equalTo(self.contendBJView);
        
    }];
    
    [leftView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.equalTo(jxpmLabel.mas_left).with.offset(-5);
        make.centerY.equalTo(jxpmLabel);
        make.height.equalTo(@1);
        make.width.equalTo(@40);
    }];
    
    [rightView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(jxpmLabel.mas_right).with.offset(5);
        make.centerY.equalTo(jxpmLabel);
        make.height.equalTo(@1);
        make.width.equalTo(@40);
    }];
    
    [self.cyrsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(jxpmLabel.mas_bottom).with.offset(8);
        make.centerX.equalTo(self.contendBJView);
    }];
    
    [self.cankaoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.cyrsLabel.mas_bottom).with.offset(8);
        make.centerX.equalTo(self.contendBJView);
    }];
    
    [cellTopView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headerBJView).with.offset(15);
        make.right.equalTo(self.headerBJView).with.offset(-15);
        make.bottom.equalTo(self.headerBJView.mas_bottom).with.offset(0);
        make.height.equalTo(@30);
    }];
    
    [@[oneLabel, twoLabel, threeLabel] mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:20 leadSpacing:20 tailSpacing:20];
    
    [@[oneLabel, twoLabel, threeLabel] mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(cellTopView);
        //        make.width.equalTo
        make.width.mas_equalTo(threeLabel.mas_width);
    }];
    
    [@[oneView, twoView] mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:(KmainScreenWidth-1)/3 leadSpacing:(KmainScreenWidth-1)/3 tailSpacing:(KmainScreenWidth-1)/3];
    
    [@[oneView, twoView] mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(cellTopView).with.offset(15);
        make.bottom.equalTo(cellTopView).with.offset(-15);
        //        make.width.equalTo
        //        make.height.mas_equalTo(threeLabel.mas_height);
        make.width.equalTo(@0.5);
    }];
    
    self.cyrsLabel.text = @"参与人数：0人";
    NSLog(@"-----%@",self.lastAmount);
   

}

- (void)contendLoadView {
    UIView * shugangView = [[UIView alloc] init];
    shugangView.backgroundColor = [UIColor lightGrayColor];
    [self.contendBJView addSubview:shugangView];
    [shugangView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contendBJView).with.offset(20);
        make.centerX.equalTo(self.contendBJView);
        make.width.equalTo(@2);
        make.height.equalTo(@35);
    }];
    
    self.zyeLsyabel = [[UILabel alloc] init];
    self.zyeLsyabel.textAlignment=NSTextAlignmentCenter;
    self.zyeLsyabel.numberOfLines = 2;
    self.zyeLsyabel.textColor = [UIColor colorWithRed:70/255.0f green:85/255.0f blue:254/255.0f alpha:1];
    self.zyeLsyabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:28];
    [self.contendBJView addSubview:self.zyeLsyabel];
    
    self.jxyeLsyabel = [[UILabel alloc] init];
    self.jxyeLsyabel.numberOfLines = 2;
    self.jxyeLsyabel.textAlignment=NSTextAlignmentCenter;
    self.jxyeLsyabel.textColor = [UIColor colorWithRed:70/255.0f green:85/255.0f blue:254/255.0f alpha:1];
    self.jxyeLsyabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:28];
    [self.contendBJView addSubview:self.jxyeLsyabel];
    
    UILabel * leftGPOSLabel = [[UILabel alloc] init];
    leftGPOSLabel.text = @"GPOS";
    leftGPOSLabel.textColor = [UIColor colorWithRed:70/255.0f green:85/255.0f blue:254/255.0f alpha:1];
    leftGPOSLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:10];
    [self.contendBJView addSubview:leftGPOSLabel];
    
    UILabel * rightGPOSLabel = [[UILabel alloc] init];
    rightGPOSLabel.text = @"GPOS";
    rightGPOSLabel.textColor = [UIColor colorWithRed:70/255.0f green:85/255.0f blue:254/255.0f alpha:1];
    rightGPOSLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:10];
    [self.contendBJView addSubview:rightGPOSLabel];
    
    UIImageView * zyetitleImage = [[UIImageView alloc] init];
    zyetitleImage.image = [UIImage imageNamed:@"icon_sy_hq"];
    [self.contendBJView addSubview:zyetitleImage];
    
    UIImageView * jxyetitleImage = [[UIImageView alloc] init];
    jxyetitleImage.image = [UIImage imageNamed:@"icon_sy_hq"];
    [self.contendBJView addSubview:jxyetitleImage];
    
    UILabel * zyetitleLabel = [[UILabel alloc] init];
    zyetitleLabel.text = @"总余额";
    zyetitleLabel.textColor = [UIColor blackColor];
    zyetitleLabel.font = [UIFont systemFontOfSize:12];
    [self.contendBJView addSubview:zyetitleLabel];
    
    UILabel * jxyetitleLabel = [[UILabel alloc] init];
    jxyetitleLabel.text = @"竞选余额";
    jxyetitleLabel.textColor = [UIColor blackColor];
    jxyetitleLabel.font = [UIFont systemFontOfSize:12];
    [self.contendBJView addSubview:jxyetitleLabel];
    
    self.daojishiLabel = [[UILabel alloc] init];
    self.daojishiLabel.textColor = [UIColor redColor];
    self.daojishiLabel.font = [UIFont systemFontOfSize:12];
    [self.contendBJView addSubview:self.daojishiLabel];
    //自定义view
    self.vv1=[[UIView alloc] init];
    [self.contendBJView addSubview:self.vv1];
    
    self.jingxuanButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.jingxuanButton setTitle:@"竞选" forState:UIControlStateNormal];
    self.jingxuanButton.titleLabel.font = [UIFont systemFontOfSize:15];
    [self.jingxuanButton setBackgroundImage:[UIImage imageNamed:@"icon_anniu_jx"] forState:UIControlStateNormal];
    [self.contendBJView addSubview:self.jingxuanButton];
    [self.jingxuanButton addTarget:self action:@selector(jingxuanButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    if (IS_IPHONE5) {
        [self.zyeLsyabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contendBJView).with.offset(15);
            make.left.equalTo(self.contendBJView).with.offset(10);
            make.right.equalTo(shugangView.mas_left).with.offset(-10);
        }];
        
        [self.jxyeLsyabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contendBJView).with.offset(15);
            make.right.equalTo(self.contendBJView).with.offset(-10);
            make.left.equalTo(shugangView.mas_right).with.offset(10);
        }];
        
        [leftGPOSLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.zyeLsyabel.mas_bottom).with.offset(5);
            make.centerX.equalTo(self.zyeLsyabel);
        }];
        [rightGPOSLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.top.equalTo(self.jxyeLsyabel.mas_bottom).with.offset(5);
            make.centerX.equalTo(self.jxyeLsyabel);
            make.centerY.equalTo(leftGPOSLabel);
        }];
        
        [zyetitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(leftGPOSLabel.mas_bottom).with.offset(10);
            make.centerX.equalTo(self.zyeLsyabel);
        }];
        
        [jxyetitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(rightGPOSLabel.mas_bottom).with.offset(10);
            make.centerX.equalTo(self.jxyeLsyabel);
        }];
        
        [zyetitleImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(zyetitleLabel);
            make.right.equalTo(zyetitleLabel.mas_left).with.offset(-5);
            
        }];
        
        [jxyetitleImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(jxyetitleLabel);
            make.right.equalTo(jxyetitleLabel.mas_left).with.offset(-5);
            
        }];
        
        [self.jingxuanButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.contendBJView);
            make.top.equalTo(jxyetitleImage.mas_bottom).with.offset(10);
            make.left.equalTo(self.contendBJView).with.offset(40);
            make.right.equalTo(self.contendBJView).with.offset(-40);
            //            make.height.equalTo(@30);
            
        }];
        
        [self.daojishiLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.contendBJView);
            make.top.equalTo(self.jingxuanButton.mas_bottom).with.offset(-5);
            
        }];
        [self.vv1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.contendBJView);
            make.top.equalTo(self.jingxuanButton.mas_bottom).with.offset(-5);
            make.width.equalTo(@100);
            make.height.equalTo(@30);
            
        }];
        
        
    }else {
        
        [self.zyeLsyabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contendBJView).with.offset(25);
            make.left.equalTo(self.contendBJView).with.offset(10);
            make.right.equalTo(shugangView.mas_left).with.offset(-10);
        }];
        
        [self.jxyeLsyabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contendBJView).with.offset(25);
            make.right.equalTo(self.contendBJView).with.offset(-10);
            make.left.equalTo(shugangView.mas_right).with.offset(10);
        }];
        
        [leftGPOSLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.zyeLsyabel.mas_bottom).with.offset(0);
            make.centerX.equalTo(self.zyeLsyabel);
        }];
        [rightGPOSLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.top.equalTo(self.jxyeLsyabel.mas_bottom).with.offset(5);
            make.centerX.equalTo(self.jxyeLsyabel);
            make.centerY.equalTo(leftGPOSLabel);
        }];
        
        [zyetitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(leftGPOSLabel.mas_bottom).with.offset(10);
            make.centerX.equalTo(self.zyeLsyabel);
        }];
        
        [jxyetitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(rightGPOSLabel.mas_bottom).with.offset(10);
            make.centerX.equalTo(self.jxyeLsyabel);
        }];
        
        [zyetitleImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(zyetitleLabel);
            make.right.equalTo(zyetitleLabel.mas_left).with.offset(-5);
            
        }];
        
        [jxyetitleImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(jxyetitleLabel);
            make.right.equalTo(jxyetitleLabel.mas_left).with.offset(-5);
            
        }];
        
        [self.jingxuanButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.contendBJView);
            make.top.equalTo(jxyetitleImage.mas_bottom).with.offset(10);
            
        }];
        
        [self.daojishiLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.contendBJView);
            make.top.equalTo(self.jingxuanButton.mas_bottom).with.offset(-8);
            
            
        }];
        [self.vv1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.contendBJView);
            make.top.equalTo(self.jingxuanButton.mas_bottom).with.offset(-8);
            make.width.equalTo(@100);
            make.height.equalTo(@30);
            
        }];
        
    }
    

    
    
    if (self.totalBalance == nil) {
        self.totalBalance = @"0";
    }
    if (self.JXBalance == nil) {
        self.JXBalance  = @"0";
    }
    self.zyeLsyabel.text = self.totalBalance;
    self.jxyeLsyabel.text = self.JXBalance;
//    self.daojishiLabel.text = @"倒计时";
    
}

- (void)footerLoadView {
    self.footerBGView = [[UIView alloc] init];
    NSLog(@"totasiz---%@",self.oneTotalSize);
    if ([self.oneTotalSize isEqualToString:@"0"]) {
        self.footerBGView.frame = CGRectMake(0,0, KmainScreenWidth, 230);

    }else {

        self.footerBGView.frame = CGRectMake(0,0, KmainScreenWidth, 70);
    }
    
    
    self.footerBGView.backgroundColor = [UIColor colorWithRed:244/255.0f green:244/255.0f blue:244/255.0f alpha:1];;
    self.tableView.tableFooterView = self.footerBGView;
    
    if ([self.oneTotalSize isEqualToString:@"0"]) {
        [self.tableView reloadData];
        self.qseView = [[UIView alloc] init];
        self.qseView.backgroundColor = [UIColor colorWithWhite:0.93 alpha:1];
        self.qseView.layer.cornerRadius = 5;

        [self.footerBGView addSubview:self.qseView];
        [self.qseView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.footerBGView).with.offset(-35);
            make.left.equalTo(self.footerBGView).with.offset(15);
            make.right.equalTo(self.footerBGView).with.offset(-15);
            //                        make.bottom.equalTo(self.view).with.offset(-44);
            make.height.equalTo(@250);
        }];

        UIImageView * qsyimage = [[UIImageView alloc] init];
        [self.qseView addSubview:qsyimage];
        [qsyimage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.qseView);
            make.centerY.equalTo(self.qseView);
            make.height.equalTo(@80);
            make.width.equalTo(@80);
        }];
        qsyimage.image = [UIImage imageNamed:@"icon_zwmingxi"];

        UILabel * qsyLabel= [[UILabel alloc] init];
        qsyLabel.text = @"暂无数据";
        qsyLabel.font = [UIFont systemFontOfSize:13.f];
        qsyLabel.textColor = [UIColor grayColor];
        [self.qseView addSubview:qsyLabel];
        [qsyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.qseView);
            make.top.equalTo(qsyimage.mas_bottom).with.offset(5);

        }];
        
        return;
    }
    
    UIView * footerCellView = [[UIView alloc] init];
    footerCellView.backgroundColor = [UIColor whiteColor];
    footerCellView.layer.cornerRadius = 3;
    [self.footerBGView addSubview:footerCellView];
    [footerCellView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.footerBGView).with.offset(0);
        make.left.equalTo(self.footerBGView).with.offset(15);
        make.right.equalTo(self.footerBGView).with.offset(-15);
        make.bottom.equalTo(self.footerBGView).with.offset(-5);
    }];
    
   
    self.syyButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.syyButton setTitle:@"上一页" forState:UIControlStateNormal];
    self.syyButton.titleLabel.font = [UIFont systemFontOfSize: 13.0];
    [self.syyButton setTitleColor:[UIColor grayColor]forState:UIControlStateNormal];
    [footerCellView addSubview:self.syyButton];
    
    self.xyyButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.xyyButton setTitle:@"下一页" forState:UIControlStateNormal];
    self.xyyButton.titleLabel.font = [UIFont systemFontOfSize: 13.0];
    [self.xyyButton setTitleColor:[UIColor grayColor]forState:UIControlStateNormal];
    [footerCellView addSubview:self.xyyButton];
    
    [@[self.syyButton, self.xyyButton] mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:(KmainScreenWidth-100)/3 leadSpacing:(KmainScreenWidth-90)/3 tailSpacing:(KmainScreenWidth-100)/3];
    
    [@[self.syyButton, self.xyyButton] mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(footerCellView).with.offset(7);
        make.width.equalTo(@50);
    }];
    //
    [self.syyButton addTarget:self action:@selector(syyButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.xyyButton addTarget:self action:@selector(xyyButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    UIView * oneView = [[UIView alloc] init];
    oneView.backgroundColor = [UIColor grayColor];
    [footerCellView addSubview:oneView];
    
    UIView * twoView = [[UIView alloc] init];
    twoView.backgroundColor = [UIColor grayColor];
    [footerCellView addSubview:twoView];
    //
    [@[oneView, twoView] mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:(KmainScreenWidth-31)/3 leadSpacing:(KmainScreenWidth-31)/3 tailSpacing:(KmainScreenWidth-31)/3];
    
    [@[oneView, twoView] mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.syyButton.mas_bottom).with.offset(10);
        make.bottom.equalTo(footerCellView).with.offset(-10);
        //        make.width.equalTo
        //        make.height.mas_equalTo(threeLabel.mas_height);
        make.width.equalTo(@0.5);
    }];
    
    self.xingxingImage = [[UIImageView alloc] init];
    self.xingxingImage.image = [UIImage imageNamed:@"icon_ziji"];
    [footerCellView addSubview:self.xingxingImage];
    [self.xingxingImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(oneView);
        make.left.equalTo(footerCellView).with.offset(15);
    }];
    
    self.zjshuziLabel = [[UILabel alloc] init];
    self.zjshuziLabel.textColor = [UIColor blueColor];
    self.zjshuziLabel.font = [UIFont systemFontOfSize:13];
    [footerCellView addSubview:self.zjshuziLabel];
    [self.zjshuziLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(oneView);
        make.left.equalTo(self.xingxingImage.mas_right).with.offset(3);
    }];
    
    self.zjContentLabel = [[UILabel alloc] init];
    self.zjContentLabel.textColor = [UIColor blueColor];
    self.zjContentLabel.font = [UIFont systemFontOfSize:13];
    [footerCellView addSubview:self.zjContentLabel];
    [self.zjContentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(oneView);
        make.left.equalTo(self.zjshuziLabel.mas_right).with.offset(3);
    }];
    
    self.ziNameLabel = [[UILabel alloc] init];
    self.ziNameLabel.textColor = [UIColor blueColor];
    self.ziNameLabel.font = [UIFont systemFontOfSize:13];
    self.ziNameLabel.textAlignment=NSTextAlignmentCenter;
    [footerCellView addSubview:self.ziNameLabel];
    [self.ziNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(oneView);
        make.left.equalTo(oneView.mas_right).with.offset(5);
        make.right.equalTo(twoView.mas_left).with.offset(-5);
    }];
    
    self.ziGPOSLabel = [[UILabel alloc] init];
    self.ziGPOSLabel.textColor = [UIColor blueColor];
    self.ziGPOSLabel.font = [UIFont systemFontOfSize:13];
    self.ziGPOSLabel.textAlignment=NSTextAlignmentCenter;
    [footerCellView addSubview:self.ziGPOSLabel];
    [self.ziGPOSLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(oneView);
        make.left.equalTo(twoView.mas_right).with.offset(5);
        make.right.equalTo(footerCellView).with.offset(-5);
    }];
    
    if (self.ison == 0) {
        NSLog(@"请求phase");
        self.jingxuanButton.userInteractionEnabled = NO;
        self.jingxuanButton.layer.cornerRadius  = 10;
    }else if (self.ison == 2){
        self.jingxuanButton.userInteractionEnabled = YES;
        self.jingxuanButton.layer.cornerRadius  = 10;
    }

}



-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.modelArr.count;
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{//rankingCell
    
    
    pageJxViewCell * cell = [[pageJxViewCell alloc] init];
 
    cell = [tableView dequeueReusableCellWithIdentifier:@"pagejxCell"];
    if (!cell) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"pageJxViewCell" owner:self options:nil] firstObject];
    }
   
    cell.nameLable.text = [self.modelArr[indexPath.row] nickName];
//     NSNumber * nsNumber1 = @([self.modelArr[indexPath.row] amount]);
//    NSDecimalNumber * number = [dic objectForKey:@"amount"];
    cell.GPOSLabel.text = [NSString stringWithFormat:@"%@",[self.modelArr[indexPath.row] amount]];

   [cell.touxiangImage sd_setImageWithURL:[NSURL URLWithString:[self.modelArr[indexPath.row] portrait]] placeholderImage:[UIImage imageNamed:@"icon_tx_jx"]];
    cell.touxiangImage.image = [UIImage imageNamed:@"icon_tx_jx"];
    cell.touxiangImage.layer.cornerRadius = 10;
    cell.touxiangImage.clipsToBounds=YES;
    cell.paimingLabel.text = [NSString stringWithFormat:@"%d",[self.modelArr[indexPath.row] rank]];;
    
    if ([self.modelArr[indexPath.row]rank] == 1) {
        cell.huangguanImage.image = [UIImage imageNamed:@"icon_jin"];
        cell.huangguanImage.hidden=NO;
        
    }else if ([self.modelArr[indexPath.row]rank] == 2) {
        cell.huangguanImage.image = [UIImage imageNamed:@"icon_yin"];
         cell.huangguanImage.hidden=NO;
    }else if ([self.modelArr[indexPath.row]rank] == 3) {
        cell.huangguanImage.image = [UIImage imageNamed:@"icon_tong"];
         cell.huangguanImage.hidden=NO;
    }else{
        
        cell.huangguanImage.hidden=YES;
        
    }
 
    
    
    return cell;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 40;
}

//竞选规则
- (void)guizeButtonAction:(UIButton *)sender{
    jxgzViewController * VC  = [[jxgzViewController alloc] init];
    [self.navigationController pushViewController:VC animated:YES];
    
    
}
//竞选按钮的方法
- (void)jingxuanButtonAction:(UIButton *)sender {
    
    if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"status"] intValue] ==2 ) {
        jymimaViewController * jymimaVC = [[jymimaViewController alloc] init];
        [self.navigationController pushViewController:jymimaVC animated:YES];
        
    }else if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"status"] intValue] ==1 ){
        
        canyujxViewController * huaZhuanVC = [[canyujxViewController alloc] init];
        [self.navigationController pushViewController:huaZhuanVC animated:YES];
        
    }
    
}



//shang
- (void)syyButtonAction:(UIButton *)sender {
    self.syyButton.userInteractionEnabled =NO;
    [self performSelector:@selector(SyyButtonAction)withObject:nil afterDelay:1.0f];
    
}

- (void)SyyButtonAction{
    self.page = self.page-1;
    [self loadRankData];
    NSLog(@"page--%d",self.page);
    
}
//xia
- (void)xyyButtonAction:(UIButton *)sender {
    self.xyyButton.userInteractionEnabled =NO;
    [self performSelector:@selector(XyyButtonAction)withObject:nil afterDelay:1.0f];
    
//    [self.tableView reloadData];
}
- (void)XyyButtonAction{
    self.page = self.page+1;
    
    [self loadRankData];
    NSLog(@"page--%d",self.page);
    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
